package com.kun.service_order.controller;


import com.kun.service_order.service.TPayLogService;
import com.kun.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 支付日志表 前端控制器
 * </p>
 *
 * @author dmk
 * @since 2021-10-31
 */
@RestController
@RequestMapping("/service_order/t-pay-log")
@CrossOrigin
public class TPayLogController {
    @Autowired
    private TPayLogService payLogService;
    //生成二维码
    @GetMapping("createNative/{orderNo}")
    public R createNative(@PathVariable String orderNo){
       Map map= payLogService.createNative(orderNo);
        return R.ok().data("map",map);
    }

    @GetMapping("queryPayStatus/{orderNo}")
    public R queryPayStatus(@PathVariable String orderNo){
        Map<String, String> map = payLogService.queryPayStatus(orderNo);
        if (map==null){
            return R.error().message("支付出错了");
        }if (map.get("trade_state").equals("SUCCESS")){
            payLogService.updateOrdersStatus(map);
            return R.ok().message("支付成功");
        }
        return R.ok().code(25000).message("支付中");
    }
}

